//
//  EXT+UIBarButtonItem.swift
//  sinaweibo
//
//  Created by Reality on 2017/6/29.
//  Copyright © 2017年 wangjing. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(imgName : String?,title:String?,target:Any?,action:Selector){
        
        let button = UIButton()
        
        button.addTarget(target,action:action, for:UIControlEvents.touchUpInside)
        
        
        if let img = imgName {
            button.setImage(UIImage(named:img), for: UIControlState.normal)
            button.setImage(UIImage(named:"\(img)_highlighted"), for: UIControlState.highlighted)
        }
        
        if let tit = title {
            button.setTitle(tit, for: UIControlState.normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            button.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            button.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        }
        button.sizeToFit()
        /// 实例化
        self.init(customView: button)
        
        
        
    }
    
}
